package thread_pool;

import java.util.LinkedList;

public class PoolWorker extends Thread {

	private LinkedList<Runnable> queue = null;

	public PoolWorker(LinkedList<Runnable> queue) {
		this.queue = queue;
	}

	
	@Override
	public void run() {
		Runnable runner;

		while ( true ) {
			synchronized ( queue ) {
				if ( queue.isEmpty() ) {
					try {
						queue.wait();
					}
					catch (InterruptedException ie) {
//						ie.printStackTrace();
					}
				}

				runner = queue.removeFirst();
			}

			try {
				runner.run();
			} catch (RuntimeException re) {
//				re.printStackTrace();
			}
		}
	}
	
}
